﻿using CoreApi;
using CoreApi.Meta;
using CoreService.Models;
using System;
using System.Configuration;
using System.Web.Http;

namespace CoreService.Controllers
{
    public class PMWechatServiceController : BaseWechatController
    {
        private IPropertyManagerService _propertyManagerService = null;
        public PMWechatServiceController(IPropertyManagerService service)
        {
            this._propertyManagerService = service;
            _appKeys = ConfigurationManager.AppSettings["pmKey"].Split(';');
        }

        [HttpPost]
        public IHttpActionResult CheckRegisterMobile([FromBody]RegisterMobileCheckRequest request)
        {
            try
            {
                ReturnValue rv1=CheckRequest(request);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._propertyManagerService.CheckRegisterMobile(request.RegisterMobile);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [HttpPost]
        public IHttpActionResult BindWechat([FromBody]BindWechatRequest request)
        {
            try
            {
                ReturnValue rv1 = CheckRequest(request);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._propertyManagerService.BindWechat(request.RegisterMobile,request.WechatUnionId);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [HttpPost]
        public IHttpActionResult WechatServiceSheetList([FromBody]ServiceSheetListRequest request)
        {
            try
            {
                ReturnValue rv1=CheckWechatRequest(request);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._propertyManagerService.WechatServiceSheetList(request.WechatUnionId,request.Status,request.TimeRange);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [HttpPost]
        public IHttpActionResult WechatServiceSheetInfo([FromBody]ServiceSheetInfoRequest request)
        {
            try
            {
                ReturnValue rv1 = CheckWechatRequest(request);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._propertyManagerService.WechatServiceSheetInfo(request.WechatUnionId, request.ServiceSheetId);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [HttpPost]
        public IHttpActionResult WechatServiceSheetOptList([FromBody]ServiceSheetInfoRequest request)
        {
            try
            {
                ReturnValue rv1 = CheckWechatRequest(request);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._propertyManagerService.WechatServiceSheetOptList(request.WechatUnionId, request.ServiceSheetId);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }

        [HttpPost]
        public IHttpActionResult WechatServiceSheetOptResult([FromBody]ServiceSheetOptRequest request)
        {
            try
            {
                ReturnValue rv1 = CheckWechatRequest(request);
                if (!rv1.Passed) return Ok<ReturnValue>(rv1);
                ReturnValue rv = this._propertyManagerService.WechatServiceSheetOptResult(request.WechatUnionId, request.ServiceSheetId,request.OptResult,request.Comments);
                return Ok<ReturnValue>(rv);
            }
            catch (Exception ex)
            {
                return InternalServerError(ex);
            }
        }


    }
}
